<template>
  <div class="lend-refuse">
    <div class="title">拒绝理由：</div>
    <div class="refuse-box">
      <textarea class="content" maxlength="30" placeholder="请输入拒绝理由" v-model="remark" @blur="inputBlur"></textarea>
    </div>
    <div class="line"></div>

    <div class="limit-box">
      <span class="lend-time">限制借支时间：</span>
      <div class="day-box">
        <popup-picker :data="dayList" v-model="day" class="day"></popup-picker>
        <img src="../in.png" class="pic" onclick="return false"/>
      </div>
    </div>
    <div class="tip-box">提示：选择限制借支时间后，该用户在限制时间内便不可以再申请进行借支</div>

    <div class="btn-box" v-show="hideBtn">
      <button type="button" class="btn" @click="lendRefuse">提交</button>
    </div>
  </div>
</template>

<script>
  import {PopupPicker} from 'vux'
  import {baseUrl} from "../../../config/env"

  export default {
    data() {
      return {
        remark: "",
        day: [],
        dayList: [["不限制", "1天", "2天", "3天", "4天"]],
        id: "",
        userSign: "",
        docmHeight: document.documentElement.clientHeight,//默认屏幕高度
        showHeight: document.documentElement.clientHeight,//实时屏幕高度
        hideBtn: true//显示或者隐藏
      }
    },
    mounted() {
      this.day.push("不限制");
      this.id = this.$route.query.id;
      let base64 = require('js-base64').Base64;
      this.userSign = base64.decode(sessionStorage.getItem("success"));
      window.onresize = () => {
        return (() => {
          this.showHeight = document.body.clientHeight;
        })()
      };
    },
    methods: {
      inputBlur() {
        window.scrollTo(0, 0);
      },
      lendRefuse() {
        if (this.remark == "" || this.remark == undefined) {
          this.$vux.toast.text("请输入拒绝理由", "middle");
          return;
        }
        //审核借支状态
        this.$vux.loading.show({
          text: '加载中',
        });

        let time = (new Date()).getTime();
        let url = baseUrl + "/resident/update_lend_money_status?timestamp=" + time;
        let param = {"sgin": this.userSign, "timestamp": time};
        let signature = this.$signature(url, param);

        let dayNum = String(this.day) == "不限制" ? '' : String(this.day).replace("天", "");
        this.axios.get(baseUrl + "/resident/update_lend_money_status?sgin=" + this.userSign + "&status=2" + "&id=" + this.id + "&reason=" + this.remark + "&day=" + dayNum + "&auth=" + signature + "&timestamp=" + time).then((res) => {
          let resultObj = res.data;
          this.$vux.loading.hide();
          if (resultObj.code == 0) {
            if (resultObj.data == 0) {
              this.$vux.toast.text("审核失败，请重试", "middle");
            } else {
              this.$router.push({path: "/lendmanage"});
            }
          } else {
            this.$vux.toast.text(resultObj.msg, "middle");
          }
        }).catch(() => {
          this.$vux.loading.hide();
          this.$vux.toast.text("网络异常", "middle");
        });
      }
    },
    watch: {
      showHeight() {
        if (this.docmHeight > this.showHeight) {
          this.hideBtn = false;
        } else {
          this.hideBtn = true;
        }
      }
    },
    components: {
      PopupPicker
    }
  }
</script>

<style lang="stylus" scoped>
  .lend-refuse
    width: 100%
    height: 100%
    overflow: hidden
    .title
      margin-top: 0.48rem
      margin-left: 0.32rem
      margin-bottom: 0.307rem
      font-size: 0.427rem
      font-weight: 500
      color: rgba(51, 51, 51, 1)
    .refuse-box
      margin: 0 auto
      width: 93.6%
      height: 2.667rem
      margin-bottom: 0.427rem
      .content
        padding-top: 0.267rem
        padding-left: 0.267rem
        width: 97%
        height: 2.387rem
        font-size: 0.373rem
        color: rgba(51, 51, 51, 1)
        line-height: 0.48rem
        border: 0.027rem solid rgba(224, 224, 224, 1)
        border-radius: 0.053rem
        resize: none
    .line
      width: 100%
      height: 0.027rem
      background: rgba(242, 242, 242, 1)
    .limit-box
      display: flex
      justify-content: space-between
      align-items: center
      width: 100%
      height: 1.28rem
      .lend-time
        margin-left: 0.32rem
        font-size: 0.427rem
        color: rgba(51, 51, 51, 1)
      .day-box
        display: flex
        align-items: center
        margin-right: 0.32rem
        .day
          font-size: 0.427rem
          color: rgba(153, 153, 153, 1)
        .pic
          margin-left: 0.2rem
          width: 0.32rem
          height: 0.32rem
    .tip-box
      margin: 0 auto
      width: 93.33%
      font-size: 0.373rem
      line-height: 0.44rem
      color: rgba(255, 96, 96, 1)
    .btn-box
      position: absolute
      bottom: 0.64rem
      display: flex
      justify-content: center
      align-items: center
      width: 100%
      height: 1.28rem
      .btn
        width: 90.4%
        height: 1.28rem
        line-height: 1.28rem
        background: rgba(60, 175, 255, 1)
        font-size: 0.453rem
        color: rgba(255, 255, 255, 1)
        font-weight: 500
        border-radius: 0.16rem
</style>
